package com.ele.Servlet;

import com.ele.Pojo.Employee;
import com.ele.Service.impl.EmployeeServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/search")
public class QueryServlet extends HttpServlet {
    //搜索员工
    EmployeeServiceImpl employeeService =new EmployeeServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        String account=req.getParameter("account");
        String telephone=req.getParameter("telephone");
        String nickname=req.getParameter("nickname");
        System.out.println("account"+account);
        List<Employee> emps =employeeService.query(account,telephone,nickname);

        Gson gson = new Gson();
        String json =gson.toJson(emps);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }

}
